package TEST01;

import com.mysql.jdbc.Connection;
import org.junit.Test;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

//测试类
public class TestEmployee {
    @Test
    public void test() throws SQLException {
        //1.获取连接
        Connection connection = DruidUtils.getConnection();
        //2.获取prepareStatement对象
        PreparedStatement ps = connection.prepareStatement("select * from employee where name = ? and gender = ?");
        //3.设置参数
        ps.setString(1,"关羽");
        ps.setString(2,"男");
        //4.执行查询
        ResultSet resultSet = ps.executeQuery();
        //5.处理结果集
        if (resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            String gender = resultSet.getString("gender");
            double salary = resultSet.getDouble("salary");
            double bonus = resultSet.getDouble("bonus");
            Date join_date = resultSet.getDate("join_date");
            System.out.println(id + " " + name + " " + gender + " " + salary + " " + bonus + " " + join_date);
        }
        //6.关闭流
        DruidUtils.close(connection,ps,resultSet);
    }
}
